<template>
	<view>
		<u-navbar title-color="#ffffff" title="分享红包" back-text="返回" back-icon-color="#ffffff" :back-text-style="textObj"
		 :border-bottom="false" :background="background"></u-navbar>
		<view class="main-mask">
			<view class="mask-box"></view>
		</view>
		<view class="main">
			<view class="box">
				<view class="">已领/个</view>
				<view class="">{{alreadyDrawPacketCount}}</view>
			</view>
			<view class="box">
				<view class="">剩余/个</view>
				<view class="">{{enableDrawPacketCount}}</view>
				<view class="line"></view>
			</view>
		</view>
		<view class="container">
			<view class="content">
				<view class="title">
					<view class="left">
						<view v-for="(item,index) in type" :key="index" class="active">{{item}}
						</view>
					</view>
					<!-- <view class="right" @click="show = true">
						<text>{{currentDate}}</text>
						<u-icon size="18" name="arrow-down-fill" color="#E1E0E0"></u-icon>
					</view> -->
				</view>
				<view class="list">
					<view class="loading" v-if="list == '' && !fail">
						<u-loading mode="circle"></u-loading>
					</view>
					<view v-if="fail" style="padding-top: 300rpx;">
						<u-empty mode="list"></u-empty>
					</view>
					<view class="item" v-for="(item,index) in list" :key="index">
						<u-image width="68" height="68" shape="circle" :src="item.headPhoto"></u-image>
						<view class="info">
							<view>{{item.nickName}}</view>
							<view>领取时间：{{item.addTime}}</view>
						</view>
						<view class="number">{{item.promoterRedPacketCount}}个</view>
					</view>
					<u-gap height="20"></u-gap>
					<u-loadmore v-if="list != ''" :status="status"></u-loadmore>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import {appletImgUrl} from "@/common/config.js"
	let uTabOffsetTop = 44 + uni.getSystemInfoSync().statusBarHeight
	export default {
		data() {
			return {
				appletImgUrl:appletImgUrl,
				type: ['分享记录'],
				imageURL: this.imageURL,
				status: 'loading',
				show: false,
				// list: [{
				// 	name: '线上'
				// }, {
				// 	name: '线下'
				// }],
				textObj: {
					color: '#ffffff'
				},
				list: [],
				fail: false,
				background: {
					backgroundImage: 'linear-gradient(90deg, #FD3129, #FF4D46)'
				},
				alreadyDrawPacketCount: 0,
				enableDrawPacketCount: 0
			};
		},
		onLoad() {
			this.pageNo = 1
			this.getList(res => {
				if (res == '') {
					this.fail = true
					this.status = 'nomore'
					return
				}
				this.status = res.length < 10 ? 'nomore' : 'loadmore'
				this.list = res
				console.log(this.list);
			})
			this.$u.get('storeadvertisetemplate/getUserDrawPacketCount').then(res => {
				this.alreadyDrawPacketCount = res.alreadyDrawPacketCount
				this.enableDrawPacketCount = res.enableDrawPacketCount
			})
		},
		onReachBottom() {
			if (this.status == 'loading' || this.status == 'nomore') return
			this.pageNo++
			this.status = 'loading'
			this.getList(res => {
				if (res == '') {
					this.status = 'nomore'
					return
				}
				this.list = this.list.concat(res)
				this.status = 'loadmore'
			})
		},
		methods: {
			// headPhoto(item) {
			// 	return item.headPhoto ? this.imageURL + item.headPhoto : '/static/team-head-img.png'
			// },
			getList(callback) {
				this.$u.post('storeadvertisetemplate/promoterRegUserList', {
					pageNo: this.pageNo,
					pageSize: 10
				}).then(res => {
					if (res.list != '') {
						res.list.forEach(item => {
							if (item.headPhoto) {
								if (item.headPhoto.indexOf("https") != 0) {
									item.headPhoto = this.imageURL + item.headPhoto
								}
							} else {
								item.headPhoto = this.appletImgUrl+'team-head-img.png'
							}
						})
					}
					callback(res.list)
				})
			}
		}
	}
</script>

<style lang="scss">
	// .btn {
	// 	position: fixed;
	// 	width: 100%;
	// 	bottom: 0;
	// 	z-index: 2;
	// 	left: 0;
	// 	background: linear-gradient(90deg, #FD3129, #FF4D46);
	// 	border-radius: 40rpx 40rpx 0 0;

	// 	.btn-box {
	// 		line-height: 100rpx;
	// 		color: #FFFFFF;
	// 		text-align: center;
	// 		font-size: 28rpx;
	// 	}
	// }

	.container {
		position: relative;
		z-index: 1;
		top: -35rpx;

		.content {
			border-radius: 40rpx 40rpx 0px 0px;
			background-color: #FFFFFF;
			padding: 0 30rpx;

			.list {

				.loading {
					display: flex;
					justify-content: center;
					padding-top: 300rpx;
				}

				min-height: 50vh;

				.item {
					padding: 20rpx 0;
					display: flex;
					align-items: center;

					.number {
						font-size: 30rpx;
					}

					.info {
						padding: 0 30rpx;
						flex: 1;

						view {
							&:last-child {
								font-size: 24rpx;
								color: #AAAAAA;
								margin-top: 5rpx;
							}
						}
					}
				}
			}

			// .money {
			// 	view {
			// 		&:first-child {
			// 			font-size: 24rpx;
			// 		}

			// 		&:last-child {
			// 			font-weight: bold;
			// 			font-size: 30rpx;

			// 			text {
			// 				font-size: 48rpx;
			// 			}
			// 		}
			// 	}
			// }

			.tab {
				height: 82rpx;
				border-bottom: 1rpx solid #E1E0E0;
			}

			.title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 45rpx 0;
				border-bottom: 1rpx solid #E1E0E0;
				margin-bottom: 10rpx;
				// .right {
				// 	&:last-child {
				// 		padding: 5rpx 15rpx;
				// 		display: flex;
				// 		border: 1rpx solid #E1E0E0;
				// 		border-radius: 4rpx;
				// 		align-items: center;

				// 		text {
				// 			margin-right: 10rpx;
				// 		}
				// 	}

				// 	&:first-child {
				// 		font-weight: bold;
				// 		font-size: 32rpx;
				// 	}
				// }

				.left {
					display: flex;
					align-items: center;

					>view {
						color: #AAAAAA;
						position: relative;

						.icon {
							position: absolute;
							bottom: -58rpx;
							left: 50%;
							transform: translateX(-50%);
						}

						&.active {
							font-size: 36rpx;
							color: #000000;
							font-weight: bold;
						}

						&:last-child {
							// margin-left: 40rpx;
						}
					}
				}
			}
		}
	}

	.main-mask {
		background: linear-gradient(90deg, #FD3129, #FF4D46);
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		height: 50%;
	}

	.main {
		display: flex;

		.box {
			text-align: center;
			padding-bottom: 75rpx;
			padding-top: 30rpx;
			flex: 1;
			position: relative;

			.line {
				position: absolute;
				top: 50%;
				left: 0;
				transform: translateY(-50%);
				width: 1rpx;
				height: 65rpx;
				background-color: rgba($color: #ffffff, $alpha: .5);
				margin-top: -20rpx;
			}

			view {
				color: #FFFFFF;

				&:first-child {
					font-size: 24rpx;
				}

				&:nth-child(2) {
					font-size: 60rpx;
					font-weight: bold;
					// margin: 10rpx 0;
					margin-top: 5rpx;
					// margin-bottom: 15rpx;
				}

				// &:last-child {
				// 	display: flex;
				// 	justify-content: center;

				// 	navigator {
				// 		font-size: 24rpx;
				// 		border: 1rpx solid #FFFFFF;
				// 		color: #FFFFFF;
				// 		line-height: 56rpx;
				// 		border-radius: 10rpx;
				// 		// width: 170rpx;
				// 		padding: 0 60rpx;
				// 	}
				// }
			}
		}
	}
</style>
